<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@include file="/includes.jsp"%>

<script type="text/javascript">

// PickList II script (aka Menu Swapper)- By Phil Webb (http://www.philwebb.com)
// Visit JavaScript Kit (http://www.javascriptkit.com) for this JavaScript and 100s more
// Please keep this notice intact

function move(fbox, tbox) {
     var arrFbox = new Array();
     var arrTbox = new Array();
     var arrLookup = new Array();
     var i;
     for(i=0; i<tbox.options.length; i++) {
          arrLookup[tbox.options[i].text] = tbox.options[i].value;
          arrTbox[i] = tbox.options[i].text;
     }
     var fLength = 0;
     var tLength = arrTbox.length
     for(i=0; i<fbox.options.length; i++) {
          arrLookup[fbox.options[i].text] = fbox.options[i].value;
          if(fbox.options[i].selected && fbox.options[i].value != "") {
               arrTbox[tLength] = fbox.options[i].text;
               tLength++;
          } else {
               arrFbox[fLength] = fbox.options[i].text;
               fLength++;
          }
     }
     arrFbox.sort();
     arrTbox.sort();
     fbox.length = 0;
     tbox.length = 0;
     var c;
     for(c=0; c<arrFbox.length; c++) {
          var no = new Option();
          no.value = arrLookup[arrFbox[c]];
          no.text = arrFbox[c];
          fbox[c] = no;
     }
     for(c=0; c<arrTbox.length; c++) {
     	var no = new Option();
     	no.value = arrLookup[arrTbox[c]];
     	no.text = arrTbox[c];
     	tbox[c] = no;
     }
}

function selectAll(box) {
     for(var i=0; i<box.length; i++) {
     box[i].selected = true;
     }
}
</script>

<h1 class="layout">
    <logic:empty name="groupValue" property="groupId">
        Create
    </logic:empty>
    <logic:notEmpty name="groupValue" property="groupId">
        Edit
    </logic:notEmpty>
    Group
</h1>

<html:errors/>

<html:form action="group.do?method=edit" method="post">
    <table class="layout" style="background-image: url(<html:rewrite page='/icons/group-32x32.png'/>);">
        <tr>
            <th class="layout">Name:</th>
            <td class="layout"><html:text name="groupActionForm" property="name" size="80"/></td>
        </tr>
        <tr>
            <th class="layout">Description:</th>
            <td class="layout"><html:textarea name="groupActionForm" property="description" cols="60" rows="10"/></td>
        </tr>
        <tr>
            <th class="layout">Users:</th>
            <td class="layout">
                <table>
                    <tr>
                        <td>
                            <html:select multiple="true" size="10" name="groupActionForm" property="unassignedUserIds" style="width:200" ondblclick="move(document.groupValueActionForm.unassignedUserIds,document.groupValueActionForm.assignedUserIds)">
                                <html:options collection="unassignedUserPairs" property="integer" labelProperty="string"/>
                            </html:select>
                        </td>
                        <td align="center" valign="middle">
                            <input type="button" onclick="move(this.form.assignedUserIds,this.form.unassignedUserIds)" value="<<" id=button1 name=button1>
                            <input type="button" onclick="move(this.form.unassignedUserIds,this.form.assignedUserIds)" value=">>" id=button2 name=button2>
                        </td>
                        <td>
                            <html:select multiple="true" size="10" name="groupActionForm" property="assignedUserIds" style="width:200" ondblclick="move(document.groupValueActionForm.assignedUserIds,document.groupValueActionForm.unassignedUserIds)">
                                <html:options collection="assignedUserPairs" property="integer" labelProperty="string"/>
                            </html:select>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <div class="buttons">
        <html:submit property="btnSubmit" value="OK" onclick="selectAll(document.groupValueActionForm.assignedUserIds);"/>
        <html:cancel property="btnSubmit" value="Cancel"/>
    </div>
</html:form>
